
var fontBlack = 'rgba(0, 0, 0, 0.8)';

var MY_STATISTICS_STATEMENT = (function () {

    //初始化页面或切换上方菜单时调用
    function getStatisticsData() {

        var mode = $('input[name="analyseMode"][type="radio"]:checked').val();

        var postUrl = "invs_statistics_statement.do/load";
        var params = {
            /*mode: mode*/
        }
        //显示日数据
        if (mode == 1) {
            var startDate = $('#startDt').val();
            var endDate = $('#endDt').val();
            if ( startDate == "" || endDate == "") {
                return false;
            }

            if ( startDate > endDate ) {
                WeKnow.errorMsg('起始日期不能大于终止日期!');
                return false;
            }
            params.startDt = startDate;
            params.endDt = endDate;
        } else {//显示月数据
            var startDate = $('#startYm').val()+'-01';
            var endDate = $('#endYm').val()+'-01';
            if ( startDate > endDate ) {
                WeKnow.errorMsg('起始日期不能大于终止日期!');
                return false;
            }
            params.startDt = startDate;
            params.endDt = endDate;
        }

        WeKnow.loading();
        $.post(postUrl, params, function(data, status) {
            WeKnow.closeLoading();
            if (!WeKnow.filterAjaxResult(data)) return false; // session过期check
            if(data.errcode == 0) {
                //已监管、未监管机构数量
                drawInstitutionCount(data.statisticsData.isInvsList);
                //医疗机构资质已过期数量
                drawOverdueCount(data.statisticsData.overdueCnt);
                //监管执业医师数量
                drawInvsDoctorCount(data.statisticsData.invsDoctorCnt);
                //监管机构分布
                drawInstitutionPie(data.statisticsData.attrList, data.statisticsData.firstTypeList);
                //执业医师分布
                drawDoctorPie(data.statisticsData.doctorsDistribution);

                //电子处方、台账统计
                drawPrescriptionCount(data.statisticsData.prescriptionCnt);
                drawStatisticsCount(data.statisticsData.statistics);
                //获取电子病历数量
                drawMedicalHisCnt(data.statisticsData.medicalHisCnt);

                //处方违规数量排行榜
                drawPrescriptionIllegalList(data.statisticsData.preIllegalList);
                //处方申诉处理
                drawPrescriptionPie(data.statisticsData.statistics);

                //台账违规数量排行榜
                drawAccountIllegalList(data.statisticsData.accIllegalList);
                //台账申诉处理
                drawAccountPie(data.statisticsData.statistics);
            } else {
                WeKnow.systemMsg('系统异常');
            }
        });
    }

    //医疗机构资质已过期数量
    function drawOverdueCount(data) {
        if (data == undefined && data.length == 0) {
            return;
        }

        document.getElementById("overdueCnt").innerText = data;
    }

    //已监管、未监管机构数量
    function drawInstitutionCount(data) {
        if (data == undefined) {
            return;
        }

        document.getElementById("noInvsInstitutionCnt").innerText = data.type0;
        document.getElementById("invsInstitutionCnt").innerText =  data.type1;
    }

    //监管执业医师数量
    function drawInvsDoctorCount(data) {
        if (data == undefined && data.length == 0) {
            return;
        }
        document.getElementById("invsDoctorCnt").innerText = data;
    }

    //监管机构分布
    function drawInstitutionPie(outerData, innerData) {
        if (outerData == undefined || innerData == undefined) {
            return;
        }

        var namesList = [];
        var outerDataShow = [
            {'name':'公立', 'value':0}, {'name':'民营', 'value':0}
        ];
        for(var i = 0; i < outerDataShow.length; i++){
            namesList.push(outerDataShow[i].name);
            outerDataShow[i].value = i == 0 ? outerData.type0 : outerData.type1;
        }

        for(var j = 0; j < innerData.length; j++){
            namesList.push(innerData[j].name);
        }

        // 1. 实例化对象
        var myChart = echarts.init(document.getElementById("institutionPie"));
        // 2. 指定配置项和数据
        var option = {
            tooltip: {
                trigger: 'item',
                formatter: '{b}<br/>{c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                x: '4%',
                y: '8%',
                itemWidth: fontChart(0.2),
                itemHeight: fontChart(0.14),
                itemGap: fontChart(0.08),
                textStyle: {
                    fontSize: fontChart(0.15),
                    color: fontBlack,
                },
                data: namesList,
                /*formatter: function(name) {
                    // 获取legend显示内容
                    let data = option.series[0].data;
                    let total = 0;
                    let tarValue = 0;
                    for (let i = 0, l = data.length; i < l; i++) {
                        total += data[i].value;
                        if (data[i].name == name) {
                            tarValue = data[i].value;
                        }
                    }
                    let p = (tarValue / total * 100).toFixed(2);
                    return name + ' ' + ' ' + p + '%';
                },*/
            },
            series: [
                {
                    type: 'pie',
                    selectedMode: 'single',
                    radius: [0, '50%'],
                    center: ['65%', '50%'],
                    color: ['#f2b654', '#e8fb62',
                        '#56c8ce', '#5ce8c0',
                        '#99fbd0', '#cef97f',
                        '#f37096', '#4ba2d1'],
                    label: {
                        normal: {
                            show: false,
                            position: 'inner',
                            formatter: '{d}%',
                            textStyle: {
                                fontSize: fontChart(0.15),
                                color: fontBlack,
                            }
                        }
                    },
                    labelLine: {
                        normal:{
                            show: false,
                            length: fontChart(0.25),
                            length2: fontChart(0.25),
                            lineStyle: {
                                color: fontBlack,
                            },
                        },
                    },
                    data: innerData
                },
                {
                    type: 'pie',
                    radius: ['60%', '75%'],
                    center: ['65%', '50%'],
                    color: ['#FFAAAA', '#AADAFF'],
                    label: {
                        normal: {
                            formatter: '{b}\n{c} ({d}%)',
                            textStyle: {
                                fontSize: fontChart(0.15),
                                color: fontBlack,
                            }
                        }
                    },
                    labelLine: {
                        normal:{
                            length: fontChart(0.25),
                            length2: fontChart(0.25),
                            lineStyle: {
                                color: fontBlack,
                            },
                        },
                    },
                    data: outerDataShow
                }
            ]
        };
        // 3. 配置项和数据给我们的实例化对象
        myChart.setOption(option);
        // 4. 当我们浏览器缩放的时候，图表也等比例缩放
        window.addEventListener("resize", function() {
            // 让我们的图表调用 resize这个方法
            myChart.resize();
        });
    }

    //执业医师分布
    function drawDoctorPie(data) {
        var valueData = [
            {'name':'公立', 'value':0, selected: true}, {'name':'民营', 'value':0}
        ];

        var namesList = [];
        for(var i= 0; i < valueData.length;i++){
            namesList.push(valueData[i].name);
            if (data != undefined) {
                switch (i) {
                    case 0:
                        valueData[i].value = data.public == undefined ? 0 : data.public;
                        break;
                    case 1:
                        valueData[i].value = data.private == undefined ? 0 : data.private;
                        break;
                    default:
                        break
                }
            }
        }

        // 1. 实例化对象
        var myChart = echarts.init(document.getElementById("doctorPie"));
        // 2. 指定配置项和数据
        var option = {
            /*title: {
                text: '执业医师分布',
                textStyle: {
                    fontSize: fontChart(0.225),
                    fontStyle: 'normal',
                    fontWeight: 'normal',
                },
            },*/
            legend: {
                orient: 'vertical',
                x: '4%',
                y: '8%',
                itemWidth: fontChart(0.2),
                itemHeight: fontChart(0.14),
                itemGap: fontChart(0.08),
                textStyle: {
                    fontSize: fontChart(0.15),
                    color: fontBlack,
                },
                data: namesList
            },
            series: [
                {
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    color: [ "#ffaaaa", "#aadaff"],
                    label: {
                        normal: {
                            formatter: '{b}\n{c} ({d}%)',
                            textStyle: {
                                fontSize: fontChart(0.15),
                                color: fontBlack,
                            }
                        }
                    },
                    labelLine: {
                        normal:{
                            length: fontChart(0.25),
                            length2: fontChart(0.25),
                            lineStyle: {
                                color: fontBlack,
                            },
                        },
                    },
                    data: valueData
                }
            ]
        };
        // 3. 配置项和数据给我们的实例化对象
        myChart.setOption(option);
        // 4. 当我们浏览器缩放的时候，图表也等比例缩放
        window.addEventListener("resize", function() {
            // 让我们的图表调用 resize这个方法
            myChart.resize();
        });
    }

    //处方申请处理
    function drawPrescriptionPie(data) {
        if (data == null || data.length == 0) {
            return;
        }

        var valueData = [
            {'name':'未处理', 'value':0, selected: true}, {'name':'已处理', 'value':0}
        ];

        var namesList = [];
        for(var i= 0; i < valueData.length;i++){
            namesList.push(valueData[i].name);
            switch (i) {
                case 0:
                    valueData[i].value = data.preUnprocessedCnt == undefined ? 0 : data.preUnprocessedCnt;
                    break;
                case 1:
                    valueData[i].value = data.preProcessedCnt == undefined ? 0 : data.preProcessedCnt;
                    break;
                default:
                    break;
            }
        }

        // 1. 实例化对象
        var myChart = echarts.init(document.getElementById("prescriptionPie"));
        // 2. 指定配置项和数据
        var option = {
            /*title: {
                text: '处方申诉处理',
                textStyle: {
                    fontSize: fontChart(0.225),
                    fontStyle: 'normal',
                    fontWeight: 'normal',
                },
            },*/
            legend: {
                orient: 'vertical',
                x: '4%',
                y: '8%',
                itemWidth: fontChart(0.2),
                itemHeight: fontChart(0.14),
                itemGap: fontChart(0.08),
                textStyle: {
                    fontSize: fontChart(0.15),
                    color: fontBlack,
                },
                data: namesList
            },
            series: [
                {
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    color: [ "#ffab72", "#8dec9a"],
                    label: {
                        normal: {
                            formatter: '{b}\n{c} ({d}%)',
                            textStyle: {
                                fontSize: fontChart(0.15),
                                color: fontBlack,
                            }
                        }
                    },
                    labelLine: {
                        normal:{
                            length: fontChart(0.25),
                            length2: fontChart(0.25),
                            lineStyle: {
                                color: fontBlack,
                            },
                        },
                    },
                    data: valueData
                }
            ]
        };
        // 3. 配置项和数据给我们的实例化对象
        myChart.setOption(option);
        // 4. 当我们浏览器缩放的时候，图表也等比例缩放
        window.addEventListener("resize", function() {
            // 让我们的图表调用 resize这个方法
            myChart.resize();
        });
    }

    //台账申请处理
    function drawAccountPie(data) {
        if (data == null || data.length == 0) {
            return;
        }

        var valueData = [
            {'name':'未处理', 'value':0, selected: true}, {'name':'已处理', 'value':0}
        ];

        var namesList = [];
        for(var i= 0; i < valueData.length;i++){
            namesList.push(valueData[i].name);
            switch (i) {
                case 0:
                    valueData[i].value = data.accUnprocessedCnt == undefined ? 0 : data.accUnprocessedCnt;
                    break;
                case 1:
                    valueData[i].value = data.accProcessedCnt == undefined ? 0 : data.accProcessedCnt;
                    break;
                default:
                    break;
            }
        }

        // 1. 实例化对象
        var myChart = echarts.init(document.getElementById("accountPie"));
        // 2. 指定配置项和数据
        var option = {
            /*title: {
                text: '台账申诉处理',
                textStyle: {
                    fontSize: fontChart(0.225),
                    fontStyle: 'normal',
                    fontWeight: 'normal',
                },
            },*/
            legend: {
                orient: 'vertical',
                x: '4%',
                y: '8%',
                itemWidth: fontChart(0.2),
                itemHeight: fontChart(0.14),
                itemGap: fontChart(0.08),
                textStyle: {
                    fontSize: fontChart(0.15),
                    color: fontBlack,
                },
                data: namesList
            },
            series: [
                {
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    color: [ "#ffab72", "#8dec9a"],
                    label: {
                        normal: {
                            formatter: '{b}\n{c} ({d}%)',
                            textStyle: {
                                fontSize: fontChart(0.15),
                                color: fontBlack,
                            }
                        }
                    },
                    labelLine: {
                        normal:{
                            length: fontChart(0.25),
                            length2: fontChart(0.25),
                            lineStyle: {
                                color: fontBlack,
                            },
                        },
                    },
                    data: valueData
                }
            ]
        };
        // 3. 配置项和数据给我们的实例化对象
        myChart.setOption(option);
        // 4. 当我们浏览器缩放的时候，图表也等比例缩放
        window.addEventListener("resize", function() {
            // 让我们的图表调用 resize这个方法
            myChart.resize();
        });
    }

    //电子处方
    function drawPrescriptionCount(data) {
        document.getElementById("preCnt").innerText = data == undefined ? 0 : data;
    }

    //电子处方、台账统计
    function drawStatisticsCount(data) {
        if (data == undefined) {
            return;
        }

        //电子处方 累计监管、违规数量
        // document.getElementById("preCnt").innerText = data.preCnt == undefined ? 0 : data.preCnt;
        document.getElementById("preIllegalCnt").innerText = data.preIllegalCnt == undefined ? 0 : data.preIllegalCnt;
        //申诉情况 申诉、未申诉数量
        document.getElementById("preAppealCnt").innerText = data.preAppealCnt == undefined ? 0 : data.preAppealCnt;
        document.getElementById("preNoAppealCnt").innerText = data.preNoAppealCnt == undefined ? 0 : data.preNoAppealCnt;

        //卫生台账 累计监管、异常数量
        document.getElementById("accCnt").innerText = data.accCnt == undefined ? 0 : data.accCnt;
        document.getElementById("accIllegalCnt").innerText = data.accIllegalCnt == undefined ? 0 : data.accIllegalCnt;
        document.getElementById("accAppealCnt").innerText = data.accAppealCnt == undefined ? 0 : data.accAppealCnt;
        document.getElementById("accNoAppealCnt").innerText = data.accNoAppealCnt == undefined ? 0 : data.accNoAppealCnt;
        //申诉情况 申诉、未申诉数量
    }

    //获取电子病历数量
    function drawMedicalHisCnt(data) {
        document.getElementById("medicalHisCnt").innerText = data == undefined ? 0 : data;
    }

    //处方违规数量排行榜
    function drawPrescriptionIllegalList(data) {
        if(data == !undefined) {
            return;
        }

        //清空
        document.getElementById("preIllegalList").innerHTML = "";

        for (var i=0; i < data.length; i++) {
            $("#preIllegalList").append(
                " <div class='illegalLine'>"
                + "<span class='illegalFont'>" +  data[i].name + "</span>"
                + "<span class='illegalFont'>" + data[i].count + "</span>"
                + "</div>"
            );
        }
    }

    //台账违规数量排行榜
    function drawAccountIllegalList(data) {
        if(data == !undefined) {
            return;
        }

        //清空
        document.getElementById("accIllegalList").innerHTML = "";

        for (var i=0; i < data.length; i++) {
            $("#accIllegalList").append(
                " <div class='illegalLine'>"
                + "<span class='illegalFont'>" +  data[i].name + "</span>"
                + "<span class='illegalFont'>" + data[i].count + "</span>"
                + "</div>"
            );
        }
    }

    //自适应字体大小
    function fontChart(res) {
        //获取到屏幕的宽度
        var clientWidth =
            window.innerWidth ||
            document.documentElement.clientWidth ||
            document.body.clientWidth;
        if (!clientWidth) return; //报错拦截：
        var fontSize = 80 * (clientWidth / screen.width);
        return res * fontSize;
    }

    //设置时间
    function setDateTime(){
        var t = null;
        t = setTimeout(time, 1000); //開始运行
        function time() {
            clearTimeout(t); //清除定时器
            dt = new Date();
            var weekDay = new Array("日", "一", "二", "三", "四", "五", "六");
            var y = dt.getFullYear();
            var mt = dt.getMonth() + 1<10?'0'+(dt.getMonth()+ 1):dt.getMonth()+ 1;
            var day = dt.getDate()<10?'0'+dt.getDate():dt.getDate();
            var h = dt.getHours()<10?'0'+dt.getHours():dt.getHours(); //获取时
            var m = dt.getMinutes()<10?'0'+dt.getMinutes():dt.getMinutes(); //获取分
            var s = dt.getSeconds()<10?'0'+dt.getSeconds():dt.getSeconds(); //获取秒
            var week = dt.getDay();
            document.getElementById("curTime").innerHTML =
                "<span class='timeFont'>"+y+"/"+mt+"/"+day+"</span>" +
                "<span class='timeFont'>星期"+weekDay[week]+"</span>" +
                "<span class='timeFont'>"+h+":"+m+":"+s+"</span>"
            t = setTimeout(time, 1000); //设定定时器，循环运行
        }
    }

    //跳转
    function linkJump(title, status, date, otherData) {
        var today = date;// 0：今日  1：本周  2：近两个月  10：全部

        if (date == -1) {
            today = 2;
            var mode = $('input[name="analyseMode"][type="radio"]:checked').val();

            //显示日数据
            if (mode == 1) {
                var startDate = $('#startDt').val();
                var endDate = $('#endDt').val();
                if ( startDate == "" || endDate == "") {
                    return false;
                }

                if ( startDate > endDate ) {
                    WeKnow.errorMsg('起始日期不能大于终止日期!');
                    return false;
                }
            } else {//显示月数据
                var startDate = $('#startYm').val()+'-01';
                var endDate = $('#endYm').val()+'-01';
                if ( startDate > endDate ) {
                    WeKnow.errorMsg('起始日期不能大于终止日期!');
                    return false;
                }
            }

            if (otherData != undefined) {
                otherData += ";" + "dtFrom:" + startDate + ";" + "dtTo:" + endDate;
            } else {
                otherData = "dtFrom:" + startDate + ";" + "dtTo:" + endDate
            }
        }

        window.open("main.do?initPageTitle="+ title +"&today=" + today + "&status=" + status + "&otherData=" + otherData);
    }

    return {
        getStatisticsData:getStatisticsData,
        drawInstitutionPie:drawInstitutionPie,
        drawDoctorPie:drawDoctorPie,
        drawPrescriptionPie:drawPrescriptionPie,
        drawAccountPie:drawAccountPie,
        setDateTime:setDateTime,
        linkJump:linkJump,
    }
})();

$(document).ready(function () {
    /* MY_STATISTICS_STATEMENT.drawInstitutionPie(institutionPieOuterData, institutionPieInnerData);
     MY_STATISTICS_STATEMENT.drawDoctorPie(doctorPieData);
     MY_STATISTICS_STATEMENT.drawPrescriptionPie(prescriptionPieData);
     MY_STATISTICS_STATEMENT.drawAccountPie(accountPieData);*/
    MY_STATISTICS_STATEMENT.getStatisticsData();
});

$(function(){

    $('#backToWorkspace').on('click',function(){
        WeKnow.submit(
            'invs_comprehensive_application.do'
        );
    });

    MY_STATISTICS_STATEMENT.setDateTime();

    var today = new Date();
    var todayTxt = today.format('yyyy-MM-dd');
    var befday = new Date();
    befday.setDate(today.getDate()-29);
    var beforeDay = befday.format('yyyy-MM-dd');
    $('#startDt').val(beforeDay);//开始日期初始值设置
    $('#endDt').val(todayTxt);//结束日期初始值设置

    var thisYm = today.format('yyyy-MM');
    befday.setMonth(today.getMonth());
    var beforeYm = befday.format('yyyy-MM');
    $('#startYm').val(beforeYm);//开始年月初始值设置
    $('#endYm').val(thisYm);//结束年月初始值设置

    $('#startDt').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',//日期格式
        yearSuffix: '年', //年的后缀
        showMonthAfterYear: true,//是否把月放在年的后面
        maxDate: (function() {
            return todayTxt;
        })(),//最大日期
        yearRange: (function() {
            // '1990:2010'
            var year2 = today.getFullYear();
            var year1 = today.getFullYear() - 100;
            return year1 + ':' + year2;
        })(),
        monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
        dayNamesMin: ['日','一','二','三','四','五','六'],
        beforeShow: function(dateText, inst){
            $("#ui-datepicker-div").removeClass('month');
        },
        onUpdatedDatepicker: function(_year, _month, _calendar) {
        },
        onSelect: function(selectedDate) {
            $("#startModalDt").datepicker('setDate', selectedDate);
            //开始日期大于结束日期时重设结束日期
            if (selectedDate.format('yyyy-MM-dd') > $('#endDt').val()) {
                $("#endDt").datepicker('setDate', selectedDate);
                $("#endModalDt").datepicker('setDate', selectedDate);
            }
            MY_STATISTICS_STATEMENT.getStatisticsData();
        }
    });

    $('#endDt').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',//日期格式
        yearSuffix: '年', //年的后缀
        showMonthAfterYear: true,//是否把月放在年的后面
        maxDate: (function() {
            return todayTxt;
        })(),//最大日期
        yearRange: (function() {
            // '1990:2010'
            var year2 = today.getFullYear();
            var year1 = today.getFullYear() - 100;
            return year1 + ':' + year2;
        })(),
        monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
        dayNamesMin: ['日','一','二','三','四','五','六'],
        beforeShow: function(dateText, inst){
            $("#ui-datepicker-div").removeClass('month');
        },
        onUpdatedDatepicker: function(_year, _month, _calendar) {
        },
        onSelect: function(selectedDate) {
            $("#endModalDt").datepicker('setDate', selectedDate);
            //开始日期大于结束日期时重设结束日期
            if (selectedDate.format('yyyy-MM-dd') < $('#startDt').val()) {
                $("#startDt").datepicker('setDate', selectedDate);
                $("#startModalDt").datepicker('setDate', selectedDate);
            }
            MY_STATISTICS_STATEMENT.getStatisticsData();
        }
    });

    $('#startYm').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm',//日期格式
        yearSuffix: '年', //年的后缀
        showMonthAfterYear: true,//是否把月放在年的后面
        maxDate: "+0D",//最大日期
        yearRange: (function() {
            // '1990:2010'
            var year2 = today.getFullYear();
            var year1 = today.getFullYear() - 100;
            return year1 + ':' + year2;
        })(),
        monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
        showButtonPanel: true,
        closeText: '选择',
        currentText: '本月',
        isSelMon: 'true',
        beforeShow: function(dateText, inst){
            $("#ui-datepicker-div").addClass('month');
        },
        onClose: function(dateText, inst) {
            var month = $("#ui-datepicker-div .ui-datepicker-month option:selected").val();//得到选中的月份值
            var year = $("#ui-datepicker-div .ui-datepicker-year option:selected").val();//得到选中的年份值
            if ((parseInt(month)+1)  < 10) {
                var months = '0'+ (parseInt(month)+1);
            } else {
                months = (parseInt(month))+1;
            }
            var selectYm = year+'-'+months;
            $('#startYm').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
            $('#startModalYm').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
            //开始日期大于结束日期时重设结束日期
            if (selectYm > $('#endYm').val()) {
                $("#endYm").val(selectYm);
                $("#endModalYm").val(selectYm);
            }
            MY_STATISTICS_STATEMENT.getStatisticsData();
        }
    });

    $('#endYm').datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: 'yy-mm-dd',//日期格式
        yearSuffix: '年', //年的后缀
        showMonthAfterYear: true,//是否把月放在年的后面
        maxDate: "+0D",//最大日期
        yearRange: (function() {
            // '1990:2010'
            var year2 = today.getFullYear();
            var year1 = today.getFullYear() - 100;
            return year1 + ':' + year2;
        })(),
        monthNamesShort: ['01','02','03','04','05','06','07','08','09','10','11','12'],
        showButtonPanel: true,
        closeText: '选择',
        currentText: '本月',
        isSelMon: 'true',
        beforeShow: function(dateText, inst){
            $("#ui-datepicker-div").addClass('month');
        },
        onClose: function(dateText, inst) {
            var month = $("#ui-datepicker-div .ui-datepicker-month option:selected").val();//得到选中的月份值
            var year = $("#ui-datepicker-div .ui-datepicker-year option:selected").val();//得到选中的年份值
            if ((parseInt(month)+1)  < 10) {
                var months = '0'+ (parseInt(month)+1);
            } else {
                months = (parseInt(month))+1;
            }
            var selectYm = year+'-'+months;
            $('#endYm').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
            $('#endModalYm').val(selectYm);//给input赋值，其中要对月值加1才是实际的月份
            //开始日期大于结束日期时重设结束日期
            if (selectYm < $('#startYm').val()) {
                $("#startYm").val(selectYm);
                $("#startModalYm").val(selectYm);
            }
            MY_STATISTICS_STATEMENT.getStatisticsData();
        }
    });

    MY_STATISTICS_STATEMENT.getStatisticsData();

    //切换日月
    $('input[name="analyseMode"][type="radio"]').on('change', function(){
        var mode = $('input[name="analyseMode"][type="radio"]:checked').val();
        if (mode == 1) {
            $('.month-row').hide();
            $('.choose-month').hide();
            $('.day-row').show();
            $('.choose-day').show();
        } else {
            $('.day-row').hide();
            $('.choose-day').hide();
            $('.month-row').show();
            $('.choose-month').show();
        }
        MY_STATISTICS_STATEMENT.getStatisticsData();
    })

    //选择日期范围
    $('.choose-day').on('click', function(){
        var days = $(this).data('days');
        var today = new Date();
        var todayTxt = today.format('yyyy-MM-dd');

        if (days == 0) {
            $('#startDt').val(todayTxt);//开始日期初始值设置
            $('#endDt').val(todayTxt);//结束日期初始值设置
            $('#startModalDt').val(todayTxt);//开始日期初始值设置
            $('#endModalDt').val(todayTxt);//结束日期初始值设置
        } else {
            today.setDate(today.getDate()-days);
            var beforeDay = today.format('yyyy-MM-dd');
            $('#startDt').val(beforeDay);//开始日期初始值设置
            $('#endDt').val(todayTxt);//结束日期初始值设置
            $('#startModalDt').val(beforeDay);//开始日期初始值设置
            $('#endModalDt').val(todayTxt);//结束日期初始值设置
        }
        MY_STATISTICS_STATEMENT.getStatisticsData();
    })

    //选择日期范围
    $('.choose-month').on('click', function(){
        var months = $(this).data('months');
        var today = new Date();
        var todayYmTxt = today.format('yyyy-MM');

        if (months == 0) {
            $('#startYm').val(todayYmTxt);//开始日期初始值设置
            $('#endYm').val(todayYmTxt);//结束日期初始值设置
            $('#startModalYm').val(todayYmTxt);//开始日期初始值设置
            $('#endModalYm').val(todayYmTxt);//结束日期初始值设置
        } else {
            today.setMonth(today.getMonth()-months);
            var beforeYm = today.format('yyyy-MM');
            $('#startYm').val(beforeYm);//开始日期初始值设置
            $('#endYm').val(todayYmTxt);//结束日期初始值设置
            $('#startModalYm').val(beforeYm);//开始日期初始值设置
            $('#endModalYm').val(todayYmTxt);//结束日期初始值设置
        }
        MY_STATISTICS_STATEMENT.getStatisticsData();
    })

    //模态框中切换日月
    $('input[name="analyseModalMode"][type="radio"]').on('change', function(){
        var mode = $('input[name="analyseModalMode"][type="radio"]:checked').val();
        if (mode == 1) {
            //页面日月切换
            $('#radioDay').prop('checked','checked');
            $('#radioMonth').closest('.no-choose').removeClass('active');
            $('#radioDay').closest('.no-choose').addClass('active');
            $('.month-row').hide();
            $('.choose-month').hide();
            $('.day-row').show();
            $('.choose-day').show();
        } else {
            //页面日月切换
            $('#radioMonth').prop('checked','checked');
            $('#radioDay').closest('.no-choose').removeClass('active');
            $('#radioMonth').closest('.no-choose').addClass('active');
            $('.day-row').hide();
            $('.choose-day').hide();
            $('.month-row').show();
            $('.choose-month').show();
        }
        MY_STATISTICS_STATEMENT.getStatisticsData();
    })
})

